import { configureStore, combineReducers } from "@reduxjs/toolkit";
import { userSlice } from "./userSlice/userSlice";
import { configSlice } from "./configSlice";
import { persistStore, persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage";

const persistConfig = {
  key: "root",
  storage,
};

const rootReducer = combineReducers({
  user: userSlice.reducer,
  config: configSlice.reducer,
});

const persistedReducer = persistReducer(persistConfig, rootReducer);

export const store = configureStore({
  reducer: persistedReducer,
  middleware(defaultMiddleware) {
    return defaultMiddleware({
      // 关闭检车 action 序列化检查
      serializableCheck: false,
    });
  },
});

export const persistor = persistStore(store);

export type RootState = ReturnType<typeof store.getState>;

export type AppDispatch = typeof store.dispatch;
